"""图片处理工具"""
import os
import random
import platform

def get_random_image_paths(directory, num_images=3):
    """
    利用 Github Actions，每日爬取 bing 壁纸，存储到 wallpapers 文件夹。
    https://github.com/AiMoneyClub/BingWallpapers
    """
    # 用于存放所有图片的列表
    image_paths = []

    # 遍历目录及其子目录
    for root, dirs, files in os.walk(directory):
        for file in files:
            # 检查文件扩展名
            if file.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp')):
                # 获取完整的图片路径并添加到列表
                image_paths.append(os.path.join(root, file))

    # 随机选择指定数量的图片路径
    random_images = random.sample(image_paths, min(num_images, len(image_paths)))

    return random_images
#########################################################
def interface_get_three_pic(count =3 ):
    """
    利用 Github Actions，每日爬取 bing 壁纸，存储到 wallpapers 文件夹。
    https://github.com/AiMoneyClub/BingWallpapers
    """
    sys = platform.system()
    if sys == "Windows":
        directory = r"D:\mp4\wallpapers"
    elif sys == "Darwin":
        directory = r"/Users/wangchuanyi/mp4/etc/BingWallpapers/wallpapers"
    else:
        directory = r"/root/bin/mycsdn_small.json"
    random_image_paths = get_random_image_paths(directory, num_images=count)
    if random_image_paths:
        print("随机选择的图片路径:")
        for path in random_image_paths:
            print(path)
    else:
        print("该目录及其子目录下没有找到任何图片文件。")
    return random_image_paths
    
# 使用示例
if __name__ == "__main__":
    interface_get_three_pic()